# coding=utf8
from tools.logger import Logger

from support_services.call_police import DingDingRobot


class ExceptBack(object):
    def __init__(self, name, **kwargs):
        self.name = name
        self.logger = Logger("except_" + name)
        self.dingding = DingDingRobot(**kwargs)

    def report(self, message, level="error", name=""):
        if level == "error":
            message = "{}检测到严重异常，{}".format(name, message)

        self.logger.info(message)

        # @TODO: 发送邮件报警
        # @TODO: 钉钉机器人
        self.dingding.send_text(message, level=level)
